//
//  InChannelCollectionReusableView.m
//  Inner  Voice
//
//  Created by Martin.Wang on 16/2/29.
//  Copyright © 2016年 徐海宇. All rights reserved.
//

#import "InChannelCollectionReusableView.h"

#import "InClassCollectionViewCell.h"

@interface InChannelCollectionReusableView ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong)NSArray *pdArray;
@end

static NSString *kcellIdentifier = @"classCellID";


@implementation InChannelCollectionReusableView

- (NSArray *)pdArray {
    if (_pdArray == nil) {
        _pdArray = @[@"电台",@"学术",@"专题",@"娱乐",@"另类",@"创作",@"品牌",@"搞笑",@"二次元",@"场景",@"自然",@"影视",@"情绪",@"3D听觉",@"音乐类型"];
    }
    return _pdArray;
}

- (IBAction)attentionChannel:(id)sender {
    

}

- (IBAction)hotChannel:(id)sender {
    
    self.attentionBtn.selected = NO;
    
    self.newsBtn.selected = NO;
    
    self.hotBtn.selected = YES;
    
    self.page = 1;
    
    self.hotChannel(self.page);
    
}

- (IBAction)newChannel:(id)sender {
    
    self.attentionBtn.selected = NO;
    
    self.newsBtn.selected = YES;
    
    self.hotBtn.selected = NO;
    
    self.page = 1;
    
    self.newChannel(self.page);
    
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
}
- (void)awakeFromNib {
    
    self.classCollectionview.delegate = self;
    
    self.classCollectionview.dataSource = self;
    
    //通过Nib生成cell，然后注册 Nib的view需要继承 UICollectionViewCell
    [self.classCollectionview registerNib:[UINib nibWithNibName:@"InClassCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:kcellIdentifier];
}

#pragma mark -CollectionView datasource
//section
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
//item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.pdArray.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    //重用cell
    InClassCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kcellIdentifier forIndexPath:indexPath];
    cell.classLabel.text = self.pdArray[indexPath.row];
    if (indexPath.row == 0) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/diantai@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 1) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/xueshu@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 2) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_zhuanti@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 3) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_yule@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 4) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_alt@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 5) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd_tech@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 6) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_fx_lb5@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 7) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_gaoxiao@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 8) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_ercy@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 9) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_changjing@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 10) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_ziran@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 11) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_yingshi@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 12) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_qingxu@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 13) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_3d@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    if (indexPath.row == 14) {
        NSString *imagePath = [NSString stringWithFormat:@"%@/pd/pd_yinyueleixing@2x.png",[[NSBundle mainBundle] resourcePath]];
        cell.classImage.image = [UIImage imageWithContentsOfFile:imagePath];
    }
    
    return cell;
}

#pragma mark - 定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    return CGSizeMake(self.frame.size.width/5, self.frame.size.height-30);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(20, 5, 10, 5);
}


@end
